<?php
/**
 * @name IndexController
 * @author duanChi <http://weibo.com/shijingye>
 * @desc 默认控制器
 * @see http://www.php.net/manual/en/class.yaf-controller-abstract.php
 */
class IndexController extends Yaf\Controller_Abstract {
	public function indexAction($value = '') {
		$_QUERY = $this->get_query_string();
		$this->getView()->assign('_QUERY',$_QUERY);
		$this->getView()->assign('_MANUAL_TEMPLATE_PATH',_MANUAL_TEMPLATE_PATH);
		$this->display('../index');
        return FALSE;
	}
	
	private function get_query_string() {
		$_result = [
			'route'	=>	[
				'module'	=>	'manual',
				'controller'	=>	'index',
				'action'	=>	'index'
			],
			'query_string'	=>	[],
			'file_exists'	=>	FALSE
		];
		$_tmp_query_string = explode('&', $_SERVER['QUERY_STRING']);
		
		if (!empty($_tmp_query_string)) {
			$_route = explode('/', array_shift($_tmp_query_string),3);
			$file = _MANUAL_TEMPLATE_PATH.DIRECTORY_SEPARATOR.$_route[0].'.'.(isset($_route[1]) ? $_route[1]: 'index');
			if (isset($_route[2]) && !empty($_route[2]) && $_route[2] != 'index') $file .= '.'.$_route[2];
			
			if (file_exists($file.'.html')) $_result['file_exists'] = TRUE;
			
			$_result['route'] = [
				'module'	=>	isset($_route[0]) ? $_route[0] : 'manual',
				'controller'	=>	isset($_route[1]) ? $_route[1] : 'index',
				'action'	=>	isset($_route[2]) ? $_route[2] : 'index'
			];
			$_result['query_string'] = $_tmp_query_string;
		}
		
		return $_result;
	}
}
